import React,{Component} from'react';
import {
  Link
} from 'react-router-dom';
import { getNotices } from 'api/user.js';
import '../../../news/notice/notice.scss';
export default class SystemInfo extends Component{
	constructor (props) {
		super(props)
		this.state={
			messList: []
		}
	}
	componentDidMount () {
		getNotices().then(res => { //用户通知中心接口
			if (res.code === 1){
				this.setState({
					messList: res.data.data
				})
			} else if(res.code === -403){
				this.props.history.push({
            pathname: '/login'
          })
			}
		})
	}
	render(){
		return(
			<div className="notice">
				<Link to='/user/message'><span className="glyphicon glyphicon-back back"></span></Link>
				<div className="news_title">
					<span>公告</span>
				</div>
				{
					this.state.messList.map((item,index) => {
						if(item.id === this.props.location.state.id) {
							return(
								<div className="notice_content" key={index}>
									<p>{item.title}</p>
									<div className="notice_con">{item.content}</div>
									<p className="notice_time">{item.time}</p>
								</div>
							)
						}
					})
				}
			</div>
		)
	}
}